package com.lyz.dataStructure.xiancheng.线程池;/**
 * @Author:759057893@qq.com Lyz
 * @Date: ${Date} 20:31
 * @Description:
 **/


import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 *@Author:759057893@qq.com Lyz
 *@Date: 2019/7/4 20:31
 *@Description:
 **/
/*
缓存线程池
 */
public class CachedThreadPoolDemo {
    public static void main(String[] args) {
        ExecutorService executorService = Executors.newCachedThreadPool();

        for (int i = 0; i < 10; i++) {
            final int index = i;
            try {
                Thread.sleep(index * 1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }

            executorService.execute(new Runnable() {
                @Override
                public void run() {
                    System.out.println(index);
                }
            });
        }
    }
}
